package com.flash.BusinessData.service.impl;


import com.flash.BusinessData.entity.CashAccrued;
import com.flash.BusinessData.entity.MarketData;
import com.flash.BusinessData.mapper.MarkeDataMapper;
import com.flash.BusinessData.service.MarketDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class MarketDataImpl implements MarketDataService {
    @Autowired
    private MarkeDataMapper markeDataMapper;

    @Override
    public List<MarketData> SelectMarketData(int page, int limit,MarketData marketData) {
        Map map =new HashMap();
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        map.put("strWhere",buildStrWhere(marketData));
        return markeDataMapper.SelectMarketData(map);
    }

    public String buildStrWhere(MarketData marketData){
        StringBuffer strWhere=new StringBuffer("");
        if(marketData.getTime()!=null && !marketData.getTime().equals(""))
        {
            strWhere.append(" and Time like '%" + marketData.getTime() + "%'");
        }if (marketData.getSecurityId()!=null && !marketData.getSecurityId().equals("")){
            strWhere.append(" and SecurityId =" + marketData.getSecurityId() );
        }
        return strWhere.toString();
    }
    @Override
    public int InsertMarkeData(MarketData marketData) {
        return markeDataMapper.InsertMarkeData(marketData);
    }


    @Override
    public int DeleteMarkeData(String marketId) {
        return markeDataMapper.DeleteMarkeData(marketId);
    }

    @Override
    public int UpdateMarkeData(MarketData marketData) {
        return markeDataMapper.UpdateMarkeData(marketData);
    }

    @Override
    public int SelectCountMarkData() {
        return markeDataMapper.SelectCountMarkData();
    }

}
